home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gs261sr1.zip / GDEVX.C < prev    next >
C/C++ Source or Header  |  1993-05-28  |  32KB  |  1,003 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gdevx.c */
  20. /* X Windows driver for Ghostscript library */
  21. /* The X include files include <sys/types.h>, which, on some machines */
  22. /* at least, define uint, ushort, and ulong, which std.h also defines. */
  23. /* std.h has taken care of this. */
  24. #include "gx.h"            /* for gx_bitmap; includes std.h */
  25. #include "memory_.h"
  26. #include "x_.h"
  27. #include "gserrors.h"
  28. #include "gsprops.h"
  29. #include "gsutil.h"        /* for props_extract */
  30. #include "gxdevice.h"
  31. #include "gdevx.h"
  32.  
  33. /* Define the maximum size of the temporary pixmap for copy_mono */
  34. /* that we are willing to leave lying around in the server */
  35. /* between uses.  (Assume 32-bit ints here!) */
  36. private int max_temp_pixmap = 20000;
  37.  
  38. /* Forward references */
  39. private int set_tile(P2(gx_device *, const gx_bitmap *));
  40. private void free_cp(P1(gx_device *));
  41. /* Screen updating machinery */
  42. #define update_init(dev)\
  43.   ((gx_device_X *)(dev))->up_area = 0,\
  44.   ((gx_device_X *)(dev))->up_count = 0
  45. #define update_flush(dev)\
  46.   if ( ((gx_device_X *)(dev))->up_area != 0 ) update_do_flush(dev)
  47. private void update_do_flush(P1(gx_device *));
  48. private void x_send_event(P2(gx_device *, Atom));
  49.  
  50. /* Procedures */
  51.  
  52. extern int gdev_x_open(P1(gx_device_X *));
  53. private dev_proc_open_device(x_open);
  54. private dev_proc_get_initial_matrix(x_get_initial_matrix);
  55. private dev_proc_sync_output(x_sync);
  56. private dev_proc_output_page(x_output_page);
  57. private dev_proc_close_device(x_close);
  58. private dev_proc_map_rgb_color(x_map_rgb_color);
  59. private dev_proc_map_color_rgb(x_map_color_rgb);
  60. private dev_proc_fill_rectangle(x_fill_rectangle);
  61. private dev_proc_tile_rectangle(x_tile_rectangle);
  62. private dev_proc_copy_mono(x_copy_mono);
  63. private dev_proc_copy_color(x_copy_color);
  64. private dev_proc_draw_line(x_draw_line);
  65. private dev_proc_put_props(x_put_props);
  66. dev_proc_get_xfont_procs(x_get_xfont_procs);
  67.  
  68. /* The device descriptor */
  69. private gx_device_procs x_procs = {
  70.     x_open,
  71.     x_get_initial_matrix,
  72.     x_sync,
  73.     x_output_page,
  74.     x_close,
  75.     x_map_rgb_color,
  76.     x_map_color_rgb,
  77.     x_fill_rectangle,
  78.     x_tile_rectangle,
  79.     x_copy_mono,
  80.     x_copy_color,
  81.     x_draw_line,
  82.     gx_default_get_bits,
  83.     gx_default_get_props,
  84.     x_put_props,
  85.     NULL,
  86.     x_get_xfont_procs
  87. };
  88.  
  89. /* The instance is public. */
  90. gx_device_X gs_x11_device = {
  91.     sizeof(gx_device_X),
  92.     &x_procs,
  93.     "x11",
  94.     (int)(8.5*FAKE_RES),
  95.     (int)(11*FAKE_RES),    /* x and y extent (nominal) */
  96.     FAKE_RES, FAKE_RES,    /* x and y density (nominal) */
  97.     no_margins,
  98.     dci_black_and_white,
  99.     0,            /* connection not initialized */
  100.     { /* image */
  101.       0, 0,            /* width, height */
  102.       0, XYBitmap, NULL,    /* xoffset, format, data */
  103.       LSBFirst, 8,        /* byte-order, bitmap-unit */
  104.       MSBFirst, 8, 1,    /* bitmap-bit-order, bitmap-pad, depth */
  105.       0, 1,            /* bytes_per_line, bits_per_pixel */
  106.       0, 0, 0,        /* red_mask, green_mask, blue_mask */
  107.       NULL,            /* *obdata */
  108.        { NULL,            /* *(*create_image)() */
  109.          NULL,            /* (*destroy_image)() */
  110.          NULL,            /* (*get_pixel)() */
  111.          NULL,            /* (*put_pixel)() */
  112.          NULL,            /* *(*sub_image)() */
  113.          NULL            /* (*add_pixel)() */
  114.        },
  115.     },
  116.     NULL, NULL,        /* dpy, scr */
  117.                 /* (connection not initialized) */
  118.     NULL,            /* vinfo */
  119.     (Colormap)None,        /* cmap */
  120.     (Window)None,        /* win */
  121.     NULL,            /* gc */
  122.     (Pixmap)0,        /* bpixmap */
  123.     0,            /* ghostview */
  124.     (Window)None,        /* mwin */
  125. #if HaveStdCMap
  126.     NULL,            /* std_cmap */
  127. #endif
  128.     identity_matrix_body,    /* initial matrix (filled in) */
  129.     (Atom)0, (Atom)0, (Atom)0,    /* Atoms: NEXT, PAGE, DONE */
  130.      { 0, 0, 0, 0 }, 0, 0,    /* update, up_area, up_count */
  131.     (Pixmap)0,        /* dest */
  132.     0L, ~0L,        /* colors_or, colors_and */
  133.      { /* cp */
  134.        (Pixmap)0,        /* pixmap */
  135.        NULL,        /* gc */
  136.        -1, -1        /* raster, height */
  137.      },
  138.      { /* ht */
  139.        (Pixmap)None,        /* pixmap */
  140.        (Pixmap)None,        /* no_pixmap */
  141.        gx_no_bitmap_id,        /* id */
  142.        0, 0, 0,            /* width, height, raster */
  143.        0, 0                /* fore_c, back_c */
  144.      },
  145.     GXcopy,            /* function */
  146.     FillSolid,        /* fill_style */
  147.     0,            /* font */
  148.     0, 0,            /* back_color, fore_color */
  149.     0, 0,            /* background, foreground */
  150.     NULL,            /* dither_colors */
  151.     0, 0,            /* color_mask, half_dev_color */
  152.     NULL,            /* dynamic_colors */
  153.     0, 0,            /* dynamic_size, dynamic_number */
  154.     0, 0,            /* borderColor, borderWidth */
  155.     NULL,            /* geometry */
  156.     128, 5,            /* maxGrayRamp, maxRGBRamp */
  157.     NULL,            /* palette */
  158.     NULL, NULL, NULL,    /* regularFonts, symbolFonts, dingbatFonts */
  159.     NULL, NULL, NULL,    /* regular_fonts, symbol_fonts, dingbat_fonts */
  160.     1, 1, 0,        /* useXFonts, useScalableFonts, logXFonts */
  161.     10.0,            /* xFontTolerance */
  162.     0.0, 0.0,        /* xResolution, yResolution */
  163.     1,            /* useBackingPixmap */
  164.     1, 1,            /* useXPutImage, useXSetTile */
  165. };
  166.  
  167. /* If XPutImage doesn't work, do it ourselves. */
  168. private void alt_put_image();
  169. #define put_image(dpy,win,gc,im,sx,sy,x,y,w,h)\
  170.   if ( xdev->useXPutImage) XPutImage(dpy,win,gc,im,sx,sy,x,y,w,h);\
  171.   else alt_put_image(dev,dpy,win,gc,im,sx,sy,x,y,w,h)
  172.  
  173.  
  174. /* Open the device.  Most of the code is in gdevxini.c. */
  175. private int
  176. x_open(gx_device *dev)
  177. {
  178.     gx_device_X *xdev = (gx_device_X *)dev;
  179.     int code = gdev_x_open(xdev);
  180.  
  181.     if (code < 0) return code;
  182.     update_init(dev);
  183.     return 0;
  184. }
  185.  
  186. /* Close the device. */
  187. private int
  188. x_close(gx_device *dev)
  189. {
  190.     gx_device_X *xdev = (gx_device_X *)dev;
  191.  
  192.     if (xdev->ghostview) x_send_event(dev, xdev->done);
  193.     if (xdev->vinfo) {
  194.     XFree(xdev->vinfo);
  195.     xdev->vinfo = NULL;
  196.     }
  197.     if (xdev->dither_colors) {
  198.     if (gx_device_has_color(xdev))
  199.         gs_free((char *)xdev->dither_colors, sizeof(x_pixel),
  200.             xdev->color_info.dither_gray, "gdev_x_gray_ramp");
  201.     else
  202.         gs_free((char *)xdev->dither_colors, sizeof(x_pixel),
  203.             xdev->color_info.dither_rgb, "gdev_x_rgb_cube");
  204.     xdev->dither_colors = NULL;
  205.     }
  206.     if (xdev->dynamic_colors) {
  207.     gs_free((char *)xdev->dynamic_colors, sizeof(XColor),
  208.         xdev->dynamic_size, "gdev_x_dynamic_colors");
  209.     xdev->dynamic_colors = NULL;
  210.     }
  211.     while (xdev->regular_fonts) {
  212.     x11fontmap *font = xdev->regular_fonts;
  213.     xdev->regular_fonts = font->next;
  214.     if (font->std_names) XFreeFontNames(font->std_names);
  215.     if (font->iso_names) XFreeFontNames(font->iso_names);
  216.     gs_free(font->x11_name, sizeof(char), strlen(font->x11_name)+1,
  217.         "gdev_x_font_x11name");
  218.     gs_free(font->ps_name, sizeof(char), strlen(font->ps_name)+1,
  219.         "gdev_x_font_psname");
  220.     gs_free((char *)font, sizeof(x11fontmap), 1, "gdev_x_fontmap");
  221.     }
  222.     while (xdev->symbol_fonts) {
  223.     x11fontmap *font = xdev->symbol_fonts;
  224.     xdev->symbol_fonts = font->next;
  225.     if (font->std_names) XFreeFontNames(font->std_names);
  226.     if (font->iso_names) XFreeFontNames(font->iso_names);
  227.     gs_free(font->x11_name, sizeof(char), strlen(font->x11_name)+1,
  228.         "gdev_x_font_x11name");
  229.     gs_free(font->ps_name, sizeof(char), strlen(font->ps_name)+1,
  230.         "gdev_x_font_psname");
  231.     gs_free((char *)font, sizeof(x11fontmap), 1, "gdev_x_fontmap");
  232.     }
  233.     while (xdev->dingbat_fonts) {
  234.     x11fontmap *font = xdev->dingbat_fonts;
  235.     xdev->dingbat_fonts = font->next;
  236.     if (font->std_names) XFreeFontNames(font->std_names);
  237.     if (font->iso_names) XFreeFontNames(font->iso_names);
  238.     gs_free(font->x11_name, sizeof(char), strlen(font->x11_name)+1,
  239.         "gdev_x_font_x1